package com.kehao.leetcode.jzoffer;

import org.junit.Test;

public class JZSolution009 {
    public int numSubarrayProductLessThanK(int[] nums, int k) {
        int count = 0;
        for (int i = 0; i < nums.length; i++) {
            int mul = nums[i];
            if(mul<k){
                count++;
            }
            for (int j = i+1; j < nums.length; j++) {
                mul*=nums[j];
                if(mul<k){
                    count++;
                }else {
                    break;
                }
            }
        }
        return count;
    }

    @Test
    public void test01(){
        int[] nums = {10,5,2,6};
        int k = 100;
        int result = numSubarrayProductLessThanK(nums, k);
        System.out.println(result);
    }

    @Test
    public void test02(){
        int[] nums = {10,9,10,4,3,8,3,3,6,2,10,10,9,3};
        int k = 19;
        int result = numSubarrayProductLessThanK(nums, k);
        System.out.println(result);
    }
}
